class Deadline < ActiveRecord::Base
  # Relations
  has_many    :uploads,
              :dependent => :nullify
  belongs_to  :teaching
  
  # Validations
  validates_not_zero      :teaching_id
  validates_presence_of   :title, :end, :teaching_id
  validates_uniqueness_of :title,
                          :scope => :teaching_id
  
  # Makes sure teaching_id is greater than zero
  #
  def teaching_id_is_not_zero
    unless self.teaching_id.nil? || self.teaching_id <= 0
      return true
    else
      self.errors.add(:teaching_id, "can't be empty")
      return false
    end
  end
  
  # Returns wether or not the deadline is expired
  #
  def is_expired?
    self.end.to_time.tomorrow < Time.now
  end
end
